package com.qf.login.controller;

import com.github.wxpay.sdk.WXPay;
import com.qf.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
public class WxController {

    @Autowired
    private WXPay wxPay;

    @GetMapping("/wxpay")
    public ResultVo getPayUrl() throws Exception {

        HashMap<String,String> data = new HashMap<>();
        data.put("body","phone");  //商品描述
        data.put("out_trade_no","202403181634002");               //使用当前用户订单的编号作为当前支付交易的交易号
        data.put("fee_type","CNY");                     //支付币种
        data.put("total_fee","1");
        data.put("trade_type","NATIVE");                //交易类型
        data.put("notify_url","http://47.118.45.73:8080/pay/callback");
        Map<String, String> map = wxPay.unifiedOrder(data);
        String payurl = map.get("code_url");
        return new ResultVo(1, "ok", payurl);
    }

}
